﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BestCode.Creds.Entities;
using BestCode.Creds.UI.ViewModel;

namespace BestCode.Creds.UI
{
    /// <summary>
    /// Interaction logic for VwEntitiesChildren.xaml
    /// </summary>
    public partial class VwEntitiesChildren : UserControl
    {
        public event EventHandler OnCloseControl;
        private readonly  VmEntityChild viewModel;

        public VwEntitiesChildren(EntityInfo entity)
        {
            InitializeComponent();
            viewModel = new VmEntityChild();
            viewModel.LoadByEntityId(entity);
            this.DataContext = viewModel;
        }


        private void CloseControl()
        {
            if (OnCloseControl != null)
                OnCloseControl(this, EventArgs.Empty);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
            fbd.SelectedPath = viewModel.SelectedItem.PicturesFolder;
            var result = fbd.ShowDialog();

            if (result.ToString().Equals("OK"))
                viewModel.SelectedItem.PicturesFolder = fbd.SelectedPath;
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            if (OnCloseControl != null)
                OnCloseControl(this, EventArgs.Empty);
        }

    }
}
